package com.soft.javase.day06.string;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/24
 */
public class StringDemo2 {
    public static void main(String[] args) {
        String[] arr1 = {"nba", "abc", "cba", "zz", "qq", "haha"};

        System.out.println("排序前:");
        System.out.println(Arrays.toString(arr1));
        Arrays.sort(arr1);
        System.out.println("排序后(自然顺序):");
        System.out.println(Arrays.toString(arr1));

        String[] arr2 = {"nba", "abc", "cba", "zz", "qq", "haha"};

        System.out.println("排序前:");
        System.out.println(Arrays.toString(arr2));
        Arrays.sort(arr2, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return s1.compareTo(s2);
            }
        });
        System.out.println("排序后(使用Comparator):");
        System.out.println(Arrays.toString(arr2));
    }
}
